//
//  LZRushCouponDetialMealsTimeCell.m
//  LzzizDemo
//
//  Created by xbnzd on 16/11/7.
//  Copyright © 2016年 xbnzd. All rights reserved.
//

#import "LZGrabCouponDetailMealsTimeCell.h"
#import "GiftListLabel.h"

@interface LZGrabCouponDetailMealsTimeCell()

@property (weak, nonatomic) IBOutlet UILabel *validityPeriodTitle;
@property (weak, nonatomic) IBOutlet UILabel *validityPeriodLabel; //有效期

@property (weak, nonatomic) IBOutlet UILabel *validExceptTitle;
@property (weak, nonatomic) IBOutlet UILabel *validExceptLabel;    //是否有列外日期

@property (weak, nonatomic) IBOutlet UILabel *everydayValidTitle;
@property (weak, nonatomic) IBOutlet UILabel *everydayValidLabel; //每天工作时间

@property (weak, nonatomic) IBOutlet UILabel *otherContentLabel;  //其他备注
@property (weak, nonatomic) IBOutlet UILabel *labMealTime;          // 用餐时间
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *otherContentLabelBottomCST;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *everydayValidLabelBottomCST;

@end

@implementation LZGrabCouponDetailMealsTimeCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [self configureLabel];
    self.labMealTime.text = LZLocalizedString(@"group_meal_time", nil);
    self.validityPeriodTitle.text = LZLocalizedString(@"mine_coupons_validity_period", nil);
    self.validExceptTitle.text = LZLocalizedString(@"mine_coupons_valid_except", nil);
    self.everydayValidTitle.text = LZLocalizedString(@"mine_coupons_everyday_valid", nil);
    
    self.validityPeriodLabel.preferredMaxLayoutWidth = SCREEN_WIDTH - 40 - [self.validityPeriodTitle intrinsicContentSize].width;
    self.validExceptLabel.preferredMaxLayoutWidth = SCREEN_WIDTH - 40 - [self.validExceptTitle intrinsicContentSize].width;
    self.everydayValidLabel.preferredMaxLayoutWidth = SCREEN_WIDTH - 40 - [self.everydayValidTitle intrinsicContentSize].width;
    
    self.otherContentLabel.preferredMaxLayoutWidth = SCREEN_WIDTH - 20;
}

- (void)loadCouponValidityPeriod:(NSString *)validityPeriodStr ValidExcept:(NSString *)validExceptStr EverydayValid:(NSString *)everydayValidStr otherContent:(NSString *)otherContent
{
    self.validityPeriodLabel.text = validityPeriodStr;

    [self setOtherContentLabelText:validExceptStr withLabel:self.validExceptLabel];
    
    self.everydayValidLabel.text = everydayValidStr;
    
    [self setOtherContentLabelText:otherContent withLabel:self.otherContentLabel];
    
}

- (void)setOtherContentLabelText:(NSString *)text withLabel:(UILabel *)label
{
    if (text.length <= 0) {
        self.everydayValidLabelBottomCST.priority = 999;
        self.otherContentLabelBottomCST.priority = 250;
        return;
    }
    self.everydayValidLabelBottomCST.priority = 250;
    self.otherContentLabelBottomCST.priority = 999;
    extern CGFloat textLineSpace;
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:text];
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    
    [style setLineSpacing:textLineSpace];
    [style setLineBreakMode:NSLineBreakByWordWrapping];
    [style setAlignment:NSTextAlignmentNatural];
    
    [attStr addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, attStr.length)];
    label.attributedText = attStr;
}

#pragma mark -
#pragma mark action
- (void)configureLabel
{
//    [self.otherContentLabel setVerticalAlignment:VerticalAlignmentTop];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
